<?php namespace Common\Model; 
use Hdphp\Model\Model;
//前台Indent模型
class Indent extends Model{
	//指定Address表名
	protected $table = 'indent';

	//自动完成
	protected $auto = array(
		//array(表单字段名,处理方法,方法类型,验证条件,处理时间) 
		array('user_uid','getUserId','method',3,1),  		//当前用户
		array('time','time','function',3,1),  				//生成时间
		array('inumber','getInumber','method',3,1),  		//订单号
		array('consignee','getConsignee','method',3,1),	 	//收货人
		array('iaddress','getAddress','method',3,1),  		//收货地址
		array('express','getExpress','method',3,1) 		    //运送方式
	);

	//设置用户id
	public function getUserId(){
		return $_SESSION['user']['uid'];;
	}
	
	//设置inumber
	public function getInumber(){
		$inumber = Cart::getOrderId();
		//将订单号存SESSION中，用于匹配订单列表
		$_SESSION['user']['inumber'] = $inumber;
		return $inumber;
	}
	
	//获取用户收货人
	public function getConsignee(){
		$uaid = q('post.uaid');
		//查询用户地址表
		$addressModel = new Address;
		return $addressModel->where('uaid',$uaid)->pluck('uname');
	}
	
	//获取用户收货地址
	public function getAddress(){
		$uaid = q('post.uaid');
		//查询用户地址表
		$addressModel = new Address;
		$address = $addressModel->where('uaid',$uaid)->find();
		//获取地址与详细地址组合
		return str_replace('|', '', $address['address']).$address['address_detail'];	
	}
	
	//运送方式
	public function getExpress(){
		$express = q('post.e');
		if($express == 8){
			return '普通快递';
		}else{
			return '顺丰';
		}
	}
	
	//执行添加
	public function store(){
		//create准备数据
		if(!$this->create()) return false;
		$total= q('post.total');
		$this->data['total'] = $total;
		//添加数据并返回id	
		return $this->add();;	
	}	
}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	